import useGlobalLoadingStateStroe from '@renderer/store/Loading/GlobalLoadingStateStroe'

export default function useFileAction(
  emits: (event: 'add', ...args: string[][]) => void
) {
  const loadingStateStroe = useGlobalLoadingStateStroe()

  // 添加文件
  async function handleAddFile() {
    const fileList = await window.api.selectMultiFile()

    if (fileList.length > 0) {
      loadingStateStroe.parseFile(() => {
        emits('add', fileList)
      })
    }
  }

  // 添加文件夹
  async function handleAddfolder() {
    const folderList = await window.api.selectMultiFolder()

    if (folderList.length > 0) {
      loadingStateStroe.parseFile(() => {
        emits('add', folderList)
      })
    }
  }

  return {
    handleAddFile,
    handleAddfolder
  }
}
